package org.issaclu.springbootmybatis.user.controller;

import org.issaclu.springbootmybatis.user.bo.UserDetailBo;
import org.issaclu.springbootmybatis.user.dto.UserDetail;
import org.issaclu.springbootmybatis.user.service.UserDetailService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/user-detail")
public class UserDetailController {

    private final UserDetailService userDetailService;

    public UserDetailController( UserDetailService userDetailService) {
        this.userDetailService = userDetailService;
    }

    @PostMapping("/insert")
    public UserDetailBo insert(UserDetailBo userDetail) throws IOException {
        MultipartFile file = userDetail.getAvatar();
        UserDetailBo detailBo = this.userDetailService.insert(userDetail,file == null? null: file.getBytes());
        detailBo.setAvatar(null);
        return detailBo;
    }

    @DeleteMapping("/delete/{id}")
    public UserDetail delete(@PathVariable String id) {
        return null;
    }

    @PostMapping("/update")
    public UserDetail update(@RequestBody UserDetail userDetail) {
        return null;
    }

    @PostMapping("/select")
    public UserDetail select(@RequestBody UserDetail userDetail) {
        return null;
    }
}
